﻿namespace Bomberman
{
    using System;
    using System.Diagnostics.Contracts;

    /// <summary>
    /// A simple class to keep track of a players kills, death and points.
    /// </summary>
    public class Score : IComparable<Score>
    {
        public readonly string Name;

        /// <summary>
        /// Initializes a new instance of the Score class.
        /// </summary>
        /// <param name="name">Name of the player</param>
        /// <param name="kills">How many kills the player has</param>
        /// <param name="deaths">How many death the player has</param>
        public Score(string name, int kills, uint deaths)
        {
            Contract.Requires(!string.IsNullOrEmpty(name));
            Name = name;
            Kills = kills;
            Deaths = deaths;
        }

        public int Kills { get; set; }

        public uint Deaths { get; set; }

        public override string ToString()
        {
            return Name;
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        [Pure]
        public int CompareTo(Score obj)
        {
            return obj.GetPoints() - GetPoints();
        }

        public override bool Equals(object obj)
        {
            return Name.Equals(obj.ToString());
        }

        /// <summary>
        /// Calculates how many points the player has.
        /// </summary>
        /// <returns>The number of points the player has</returns>
        [Pure]
        public int GetPoints()
        {
            return Kills - (int)Deaths;
        }
    }
}
